#Makefile

include ../config.mak
include sub.mak

all: libijpegd.a ijpegd libhwicodec.a

#libhwicodec.a
HWICODEC_DIR = ../hwicodec
ICOMMON_DIR = ../icommon

# libijpegd.a
INCLUDES = ${INCLUDE_COMMON} -Iinclude
INCLUDES += -I$(HWICODEC_DIR)/include
INCLUDES += -I$(ICOMMON_DIR)/include

LDFLAGS = -pthread
CFLAGS = ${CFLAGS_COMMON} $(INCLUDES)
LDFLAGS += -lm

OBJS = $(OBJS-$(IJPEGD))

$(OBJS):%.o:%.c
	$(CC) -c $(CFLAGS) -o $@ $<

libijpegd.a: $(OBJS) libhwicodec.a
	$(LD) -EL -o $@ -r -Bstatic $(OBJS) $(HWICODEC_DIR)/libhwicodec.a

libhwicodec.a:
	$(MAKE) -C $(HWICODEC_DIR)

INCLUDECLI = -Iincludecli
LDFLAGCLI = -L. -lijpegd $(LDFLAGS)
CFLAGCLI = ${CFLAGS_COMMON} $(INCLUDECLI) $(INCLUDES)

OBJCLI = ijpegd.o srccli/cliijpegd.o

$(OBJCLI):%.o:%.c
	$(CC) -c $(CFLAGCLI) -o $@ $<

ijpegd: $(OBJCLI) libijpegd.a
	$(CC) -static $(CFLAGCLI) $(LDFLAGCLI) -o $@ $(OBJCLI)

.PHONY: clean distclean
clean:
	$(MAKE) clean -C $(HWICODEC_DIR)
	-rm -f $(OBJS) $(OBJCLI)

distclean: clean
	$(MAKE) distclean -C $(HWICODEC_DIR)
	-rm -f ijpegd libijpegd.a
